import request from '@/utils/request'
import qs from 'qs';
import MD5 from 'js-md5';

// 请求地址前缀
const REQUEST_URL_PRE = "/manage/merchant";

export default {
    /**
     * 获取商户信息
     */
    fetchMerchant() {
        return request({
            url: REQUEST_URL_PRE + '/load',
            method: 'get'
        })
    },
    /**
     * 获取商户下的收款账号集合
     */
    fetchMerchantAccountList() {
        return request({
            url: REQUEST_URL_PRE + '/listAccount',
            method: 'get'
        })
    },
    /**
     * 创建收款账号
     * @param {String} zfbAccount -- 收款的支付宝账号
     */
    addMerchantAccount(zfbAccount) {
        let data = { "zfbAccount": zfbAccount };
        let requestData = qs.stringify(data);
        return request({
            url: REQUEST_URL_PRE + '/addAccount',
            method: 'post',
            data: requestData
        })
    },
    /**
     * 修改收款账号下的支付宝账号
     * @param {String} account -- 商户的收款账号
     * @param {String} zfbAccount -- 收款的支付宝账号
     */
    updateMerchantAccount(account, zfbAccount) {
        let data = { "zfbAccount": zfbAccount, "account": account };
        let requestData = qs.stringify(data);
        return request({
            url: REQUEST_URL_PRE + '/updateAccount',
            method: 'post',
            data: requestData
        })
    },
    /**
     * 删除商户下的收款账号
     * @param {String} account -- 商户的收款账号
     */
    deleteMerchantAccount(account) {
        let data = { "account": account }
        let requestData = qs.stringify(data);
        return request({
            url: REQUEST_URL_PRE + '/deleteAccount',
            method: 'post',
            data: requestData
        })
    },
    /**
     * 获取充值支付的二维码
     * @param {double}} amount -- 单位元，2位小数
     */
    getRechargePayCode(amount) {
        let data = { "amount": amount }
        //let requestData = qs.stringify(data);
        return request({
            url: "/manage/zhiFuBaoRecharge/getPayOrderInfo",
            method: "get",
            params: data
        })
    },
    /**
     * 修改登录密码
     * @param {String} newPassword -- 新的登录密码
     * @param {String} email -- 商户的注册邮箱
     */
    updateLoginPassword(newPassword, email) {
        let md5Password = MD5(email + newPassword)
        let data = { "newPassword": md5Password };
        let requestData = qs.stringify(data);
        return request({
            url: REQUEST_URL_PRE + '/updateLoginPassword',
            method: 'post',
            data: requestData
        })
    },
    // 发送收款账号app在线的心跳
    sendAccountOnLineHeartbeat(account) {
        let data = { "account": account };
        let requestData = qs.stringify(data);
        return request({
            url: REQUEST_URL_PRE + '/accountAppOnLineHeartbeat',
            method: 'post',
            data: requestData
        });
    },
    // 获取app在线状态标签
    getAccountAppOnLineStatus() {
        return h('Tag', {
            props: {
                color: _type,
                size: 'small'
            }
        }, statusMsg);
    },
    // 查询收款账号App是否在线
    loadAccountAppOnLine(account) {
        let data = { "account": account };
        return request({
            url: REQUEST_URL_PRE + '/loadAccountAppOnLine',
            method: 'get',
            params: data
        });
    }
}
